package com.itheima.day04;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class Demo8 {
    public static void main(String[] args) {
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime = " + localDateTime);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        System.out.println(formatter.format(localDateTime));
        System.out.println("======");
        System.out.println(localDateTime.format(formatter));
        System.out.println("=======");
        String s="2021/08/06 11:11:11";
        LocalDateTime dateTime = LocalDateTime.parse(s, formatter);
        boolean equals = dateTime.equals(LocalDateTime.now());
        System.out.println("equals = " + equals);
        System.out.println("=======");
        Duration duration = Duration.between(localDateTime, dateTime);
        System.out.println("duration = " + duration);
        System.out.println(duration.toDays());
        System.out.println(ChronoUnit.YEARS.between(dateTime,localDateTime));

    }
}
